home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Overloading conversion
- Date: 14 Jan 1996 19:42:35 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan14204236@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4d934v$10hs@ds2.acs.ucalgary.ca>
- <ENNO.96Jan14111826@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- <30f93747.165768512@nntp.ix.netcom.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: miker3@ix.netcom.com's message of Sun, 14 Jan 1996 17:05:03 GMT
-
- In article <30f93747.165768512@nntp.ix.netcom.com> miker3@ix.netcom.com (Mike Rubenstein) writes:
-
- enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner) wrote:
-
- |>In article <4d934v$10hs@ds2.acs.ucalgary.ca>
- hdang@acs3.acs.ucalgary.ca (Hanna Dang) writes:
- |>
- |> Is there a way to overload functions such that certain
- |> functions are called depending on the context the object are
- |> used. For example,
- |>
- |> class T {
- |> public:
- |> int& int_value() { modified = TRUE; return value;}
- |> int int_value() {return value;}
- |> private:
- |> int value;
- |> int modified;
- |> }
- |>
- |>
- |> ...
- |>
- |> T a;
- |> int test = a + 6 // int int_value should be called;
- |> a = 20 // int& int_value should be called.
- |>
- |> However, this does not work because in both case int& int_value
- |> is called. Is there another way to find out if value is changed
- |> or it's just inspected.
- |>
- |>Yes -- make the latter 'int_value' a const member-function, ie.
- |>
- |> int int_value() const {return value;}
-
- Have you tried this? If so, what compiler? I want to make sure I
- avoid it.
-
- The decision as to whether to call the const or non-const version of a
- member function is based on whether the class object is const, not on
- which side of the equal sign it appears. In both cases above, the
- non-const version will be called since a is not const.
-
- Yep, you are correct -- my previous posting was completly rubbish.
-
- Enno
-